//
// Created by guoshunw on 3/19/2021.
//
#include "InterviewTest.h"
#include <iostream>
#include "Log.h"

// http://thbecker.net/articles/rvalue_references/section_01.html
using namespace std;

int testMySmartPointer(int argc, char *argv[]) {

    int *a = new int{5};
    SmartPointer<int> sA(a);

    auto b = sA;

    auto c = b;
    auto d = c;

    cout << *sA << *b << ", use count: " << b.use_count() << ",d var: " << d.use_count() << endl;

    SmartPointer<int> sB;
    sB = d;
    try {
        cout << "sb now is: " << *sB << endl;
    } catch (const char *&exp) {
        logDebug("Got exception: %s", exp);
    }

    struct MyTest {
        int a;
        int b;
    };

    auto p = SmartPointer<MyTest>(new MyTest{3, 4});

    cout << "p member a=" << p->a << endl;

    return 0;
}

void fun(int& i){
    logDebug("Calling i=%d", i);
}

void fun(int&& i){
    logDebug("Calling i=%d", i);
}

int bar(){
    return 3;
}

int testIntVec(int arc, char* argv[]){
//    IntVec v1(10);
    IntVec v2=IntVec(20);

//    v2 = v1;

    int&& v=3 * 9;
    logDebug("type of v is %d, addr@%p", v, &v);

    fun(v);
    fun(bar());

    int a=1;
    int b=2;
    logDebug("a=%d, b=%d", a, b);

    return 0;
}

int testInterviewTest(int argc, char *argv[]){
    return testIntVec(argc, argv);
}